package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by 星月 on 2018/5/28.
 */
public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
            throws ServletException, IOException {
        //中文乱码问题
//        response.setHeader("content-type","text/html;charset=UTF-8");
        //ctrl+删除
        //shift+enter 换行
//        PrintWriter out=resp.getWriter();
//        out.write("<table>");
//        out.write("<tr>");
//        out.write(" <td>编号</td>");
//        out.write("<td>用户名</td>");
//        out.write("<td>密码</td>");
//        out.write("<td>操作1</td>");
//        out.write("<td>操作2</td>");
//        out.write("</tr>");
//        out.write("<tr>");
//        out.write("<td>1001</td>");
//        out.write("<td>li</td>");
//        out.write(" <td>123</td>");
//        out.write("<td>删除</td>");
//        out.write("<td>更新</td>");
//        out.write(" </tr>");
//        out.write("</table>");
        //查数据库并且得到userList
        Database database=new Database();
        List<User> userList=database.getUserList();
        //requset空间中新建一个名为userList的变量
        request.setAttribute("userList",userList);
        //跳转到userLisr.jsp
        request.getRequestDispatcher("/userList.jsp")
                .forward(request,response);

    }
}
